// Object.create()
const Plane = function () {
    this.blood = 100;
    this.attackLv = 1;
    this.defenceLv = 1;
}

const plane = new Plane();
plane.blood = 500;
plane.attackLv = 5;
plane.defenceLv = 4;

const anotherPlane = Object.create(plane);
console.log(anotherPlane);

Object.create = Object.create || function (obj) {
    let F = function() {}
    F.prototype = obj;
    return new F();
}

// 函数构造器
function Person(name) {
    this.name = name
}

Person.prototype.getName = () => {
    return this.name;
}

// const a = new Person('dirk');

// Object.__proto__

// new 操作符
const objectFactory = function() {
    const obj = new Object(); // clone Object.prototype
    const Constructor = [].shift.call(arguments); // 取得外部构造器 这里指向Person
    obj.__proto__ = Constructor.prototype; // 指向正确的原型
    const ret = Constructor.apply(obj,arguments); // 借用外部传入的构造器给obj设置属性
    return typeof ret === 'object' ? ret : obj;
}

const a = objectFactory(Person, 'dirk');
const b = new Person('dirk');

// const obj = { name: 'dirk' }
// const A = function() {}
// A.prototype = obj;
// const a = new A();
// console.log(a.name);

const A = function() {};
A.prototype = { name: 'dirk' }
const B = function () {};
B.prototype = new A();
const b = new B();
console.log(b.name);